from django.shortcuts import render
from rest_framework.views import APIView
# from rest_framework_jwt.views import ObtainJSONWebToken


class HomeAPIView(APIView):
    """
    get:
    系统主页--数据显示

    获取系统主页数据, status: 200(成功), return: 系统主页数据
    """

    def get(self, request):
        data = dict()
        # conn = get_redis_connection('user_info')
        # data['visits'] = int(conn.get('visits').decode()) if conn.get('visits') else 0
        # data['users'] = Users.objects.all().count()
        # data['online_users'] = OnlineUsers.objects.all().count()
        # data['assets'] = Assets.objects.all().count()
        # return Response(data=data, status=status.HTTP_200_OK)


class UserLoginView():
    """
    post:
    用户登录

    用户登录, status: 200(成功), return: Token信息
    """
    # throttle_classes = [AnonRateThrottle]

    # def post(self, request, *args, **kwargs):
    #     # 重写父类方法, 定义响应字段内容
    #     response = super().post(request, *args, **kwargs)
    #     if response.status_code == 200:
    #         conn = get_redis_connection('user_info')
    #         conn.incr('visits')
    #         return response
    #     else:
    #         if response.data.get('non_field_errors'):
    #             # 日后将增加用户多次登录错误,账户锁定功能(待完善)
    #             if isinstance(response.data.get('non_field_errors'), list) and len(
    #                     response.data.get('non_field_errors')) > 0:
    #                 if response.data.get('non_field_errors')[0].strip() == '无法使用提供的认证信息登录。':
    #                     return Response(data={'detail': '用户名或密码错误'}, status=status.HTTP_400_BAD_REQUEST)
    #         raise ValidationError(response.data)
